<?php

namespace app\admin\model\user;

use app\admin\model\User;
use app\api\model\v1\CoursesCategory;
use app\api\model\v1\MechanismCategory;
use think\Model;


class Check extends Model
{

    

    

    // 表名
    protected $name = 'user_check';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'status_text'
    ];
    

    
    public function getStatusList()
    {
        return ['0' => __('Status 0'), '1' => __('Status 1'), '-1' => __('Status -1')];
    }

    public function getTypeList()
    {
        return ['check' => __('Type check'), 'evaluation' => __('Type evaluation'), 'base' => __('Type base')];
    }

    public function getStyleList()
    {
        return ['1' => __('Style 1'), '2' => __('Style 2'), '3' => __('Style 3'), '4' => __('Style 4')];
    }

    public function getCategoryList()
    {
//        $list = MechanismCategory::order('weigh asc')->field('id,name')->select();
        $list = CoursesCategory::order('weigh asc')->field('id,name')->select();
        $categorydata = [];
        foreach ($list as $k => $v) {
            $categorydata[$v['id']] = $v;
        }
        return $categorydata;
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function getTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
        $list = $this->getTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function user()
    {
        return $this->belongsTo(User::class, 'user_id', 'id');
    }


}
